<template>
  <div
    class="m-wrap"
    :style="{ paddingLeft: paddingWidth + 'px'}"
  >
    <el-breadcrumb
      class="m-breadcrumb"
      separator="/"
    >
      <el-breadcrumb-item>CPA数据管理</el-breadcrumb-item>
      <el-breadcrumb-item>客户/渠道管理</el-breadcrumb-item>
      <el-breadcrumb-item>投放管理</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="m-container">
      <el-form
        inline
        class="m-filter"
      >
        <el-form-item>
          <el-input
            size="small"
            v-model="value"
            class="u-w300"
            placeholder="请输入客户名称、联系人或手机号"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="search"
            ></el-button>
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-upload
            :action="apiUrl.uploadChannel"
            :with-credentials="true"
            :on-success="handleSuccess"
            :on-progress="uploading"
            :beforeUpload="beforeAvatarUpload"
            :onError="uploadError"
            :show-file-list="false"
            :file-list="fileList"
          >
            <el-button size="small">导入数据</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item>
          <el-button
            size="small"
            @click="newChannel"
          >新建渠道</el-button>
        </el-form-item>
      </el-form>

      <el-table
        v-loading="loading"
        element-loading-text="拼命上传中"
        :data="tableData"
        border
      >
        <el-table-column
          type="expand"
          align="center"
        >
          <template slot-scope="props">
            <el-form
              label-position="left"
              class="m-table-expand"
              inline
            >
              <el-form-item label="渠道代码">
                <span>{{ props.row.channelCode}}</span>
              </el-form-item>
              <el-form-item label="账号">
                <span>{{ props.row.account}}</span>
              </el-form-item>
              <el-form-item label="财务类型">
                <span v-if="props.row.finType==1">公司</span>
                <span v-if="props.row.finType==2">个人</span>
              </el-form-item>
              <el-form-item label="渠道简称">
                <span>{{ props.row.name }}</span>
              </el-form-item>
              <el-form-item label="联系人">
                <span>{{ props.row.contact }}</span>
              </el-form-item>
              <el-form-item label="纳税登记号">
                <span>{{ props.row.taxId }}</span>
              </el-form-item>
              <el-form-item label="渠道主体">
                <span><span
                    v-for="item in JSON.parse(props.row.alias)"
                    :key="item.id"
                  >{{ item.name+' '}}</span></span>
              </el-form-item>
              <el-form-item label="手机号码">
                <span>{{ props.row.phone }}</span>
              </el-form-item>
              <el-form-item label="收款银行">
                <span>{{ props.row.bank }}</span>
              </el-form-item>
              <el-form-item label="渠道性质">
                <span v-if="props.row.property==1">公司</span>
                <span v-if="props.row.property==2">个人</span>
              </el-form-item>
              <el-form-item label="QQ">
                <span>{{ props.row.qq }}</span>
              </el-form-item>
              <el-form-item label="开户地址">
                <span>{{ props.row.accountAddress }}</span>
              </el-form-item>
              <el-form-item label="营业执照号">
                <span>{{ props.row.busNo }}</span>
              </el-form-item>
              <el-form-item label="邮箱">
                <span>{{ props.row.email }}</span>
              </el-form-item>
              <el-form-item label="银行账号">
                <span>{{ props.row.bankAccount}}</span>
              </el-form-item>
              <el-form-item label="证件有效期">
                <span>{{ props.row.cardExpired }}</span>
              </el-form-item>
              <el-form-item label="地址">
                <span>{{ props.row.address}}</span>
              </el-form-item>
              <el-form-item label="账户预收/抵扣">
                <span>{{ props.row.advancePayment }}</span>
              </el-form-item>
              <el-form-item label="最后更新">
                <span>{{ props.row.ltime }}</span>
              </el-form-item>
              <el-form-item label="">
                <span></span>
              </el-form-item>
              <el-form-item label="账户应收/实收">
                <span>{{ props.row.accountPayable }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="渠道代码"
          prop="channelCode"
        >
        </el-table-column>
        <el-table-column
          align="center"
          label="渠道简称"
          prop="name"
        >
        </el-table-column>
        <el-table-column
          align="center"
          label="账号"
          prop="account"
        >
        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
          width="50"
        >
          <template slot-scope="scope">
            <div @click="exitEvent(scope.row.id)"><i class="el-icon-edit"></i></div>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        class="m-pagination"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="page.currentPage"
        :page-sizes="page.sizes"
        :page-size="page.limit"
        layout="total, prev, pager, next, sizes"
        :total="page.count"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import "@/style/common.scss";
export default {
  data() {
    return {
      page: {
        sizes: [10, 20, 30, 50, 100, 500],
        offset: 1,
        limit: 10,
        count: 0,
        currentPage: 1,
        landpageName: ""
      },
      menu_nav: ["CPA数据管理", "渠道信息管理"],
      select_items: [
        {
          model_value: "",
          placeHolder: "客户",
          options: [
            {
              id: "1",
              val: "1"
            }
          ]
        }
      ],
      tableData: [],
      value: "",
      importTitleStatus: false,
      importTitleTxt: "",
      fileList: [],
      loading: false
    };
  },
  computed: {
    paddingWidth() {
      return this.$store.state.paddingWidth;
    }
  },
  created() {
    this.listInfo();
  },
  methods: {
    listInfo() {
      /*列表*/
      this.$http({
        method: "get",
        url: this.apiUrl.channelSearch,
        params: {
          offset: this.page.offset,
          limit: this.page.limit,
          val: this.value
        }
      })
        .then(res => {
          if (res.status == 200) {
            var data = res.data;
            this.page.count = data.totalNum;
            data.items.length > 0 ? (this.tableData = data.items) : null;
          }
        })
        .catch(error => {
        });
    },
    handleCurrentChange(val) {
      this.page.offset = val;
      this.listInfo();
    },
    handleSizeChange(val) {
      this.page.limit = val;
      this.listInfo();
    },
    newChannel() {
      this.$router.push({ path: "channelInfoNew" });
    },
    exitEvent(id) {
      this.$router.push({ path: "channelInfoNew", query: { channelId: id } });
    },
    search() {
      if (this.value != "") {
        this.listInfo();
      }
    },
    exitImportTitle() {
      this.importTitleStatus = false;
      this.listInfo();
    }
  }
};
</script>
